<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head th:include="public/page_css::page_css ('收货人详情查看')"/>
<meta charset="UTF-8"/>
<title>Title</title>
<!-- load css -->

<link rel="stylesheet" type="text/css" th:href="@{/plugin/layui/css/font/iconfont.css}" media="all"/>
<link rel="stylesheet" type="text/css" th:href="@{/plugin/layui/js/layui/css/layui.css}" media="all"/>
<link rel="stylesheet" type="text/css" th:href="@{/css/main.css}" media="all"/>
<body>
<div id="div3" >
    <div class="layui-fluid larry-wrapper">
        <div style="    margin-left: 10px;font-weight: bold;">
            <h4> 所属仓库管理</h4>
        </div>
        <div class="layui-card">
            <form id="form2" class="layui-form layui-form-pane" action="">
                <div>&nbsp;</div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">车牌号</label>
                        <div class="layui-input-inline">
                            <input type="text" name="cph" id="cph" placeholder="车牌号" lay-verify="required" autocomplete="off" class="layui-input " />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">司机姓名</label>
                        <div class="layui-input-inline">
                            <input type="text" name="sjxm" id="sjxm" placeholder="联系人姓名" lay-verify="required" autocomplete="off" class="layui-input "/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">司机电话</label>
                        <div class="layui-input-inline">
                            <input type="text" name="sjdh" id="sjdh"  data-required   jq-verify="required" lay-verify="required|phone|number"   placeholder="联系人电话" autocomplete="off" class="layui-input "/>
                        </div>
                    </div>
                </div>
                <input type="hidden"  th:value="${sskhid}" id="sskhid2"  name="sskhid">
                <input type="hidden" id="clid" name="id">

                <div style=" border-bottom: 1px solid; border-bottom-color: #d5cece; padding: 20px;">

                    <button class="layui-btn" jq-filter="submit" lay-submit="" lay-filter="addbtn2">添加
                    </button>
                    <button class="layui-btn" jq-filter="submit" lay-submit="" lay-filter="savebtn2">保存编辑
                    </button>
                </div>
            </form>
            <div>


                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm2">
                    <div class="layui-inline" style="width: 190px">
                        <label class="layui-form-label" style=" width: 100px;">车牌号</label>
                        <div class="layui-inline">
                            <input type="text" name="cph" placeholder="车牌号"  class="layui-input" style="width: 190px">
                        </div>
                    </div>
                    <div class="layui-inline" style="width: 190px">
                        <label class="layui-form-label" style=" width: 100px;">司机电话</label>
                        <div class="layui-inline">
                            <input type="text" name="sjdh" placeholder="司机电话"  class="layui-input" style="width: 190px">
                        </div>
                    </div>

                    <div class="layui-inline inline-search-btn"   style="  margin-top: 40px; margin-left: 40px;" >
                        <a class="layui-btn layui-btn-normal" data-type="reload" id="search_button2"> 搜索 </a>
                    </div>
                    <div class="layui-inline inline-reset-btn"  style="  margin-top: 40px;" >
                        <button type="reset" class="layui-btn layui-btn-primary" style="background-color: #40AFFE">重置</button>
                    </div>
                </form>
                <div class="layui-col-xs24" style="max-height: 300px;overflow: auto">
                    <table data-height="300" id="table2" style="word-break:break-all; word-wrap:break-word;"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript" th:src="@{/plugin/layui/js/layui/layui.js}"></script>
<script type="text/javascript" th:src="@{/plugin/layui/js/version.js}"></script>
<script th:src="@{/plugin/layui/js/common.js}"></script>
<div th:include="public/public_js::public_js"></div>

<script>
    //	回车查询
    document.onkeydown = function(event) {
        e = event ? event : (window.event ? window.event : null);
        if (e.keyCode == 13) {
            //执行的方法
            $('#search_button').click();
            $('#search_button2').click();
        }
    };



    layui.use(['myform', 'zzpUtils', 'form'], function () {
        var form = layui.form,
            zzpUtils = layui.zzpUtils;
        window.operateEvent ={

            //车辆编辑
            "click #editRow2":function (e, value, row, index) {
                $("#cph").val(row.cph);
                $("#sjdh").val(row.sjdh);
                $("#sjxm").val(row.sjxm);
                $("#clid").val(row.id);
            },
            //车辆删除
            "click #deleteBtn2": function (e, value, row, index) {
                layer.confirm('您将删除承运车辆。', {icon: 3, title: '确认删除？'}, function (index) {
                    console.log('触发了删除', index, row, value);
                    var tabledata = $table2.bootstrapTable('getData');
                    tabledata = tabledata.filter(function (item) {
                        return item.uuid !== row.uuid;
                    });
                    var id = [];
                    id.push(row.id);
                    $.ajax({
                        type: 'post',
                        url: '/zxsdwms/wmsCustomerFileCarrier/cancel',
                        contentType: "application/json",
                        async: false,
                        data: JSON.stringify({
                            ids: id,
                        }),
                        success: function (res) {
                            setTimeout(function () {
                                zzpUtils.refreshTable("#table2");
                                /*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                 parent.layer.close(index); //再执行关闭
                                 console.info(data);*/
                                top.layer.msg(res.title + "," + res.message);
                                //刷新父页面
                            }, 500);
                        }
                    })
                    layer.close(index);
                })

            },
            //车辆启用
            "click #enable2":function (e, value, row, index) {
                layer.confirm('您将启用承运车辆。', {icon: 3, title:'确认启用？'}, function(index){
                    //do something
                    var id = [];
                    id.push(row.id);
                    $.ajax({
                        type: 'post',
                        url: '/zxsdwms/wmsCustomerFileCarrier/activation',
                        contentType: "application/json",
                        async: false,
                        data: JSON.stringify({
                            ids: id,
                        }),
                        success: function (res) {

                            console.log(res);
                            setTimeout(function(){
                                /*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                 parent.layer.close(index); //再执行关闭
                                 console.info(data);*/
                                top.layer.msg(res.title+","+res.message);
                                zzpUtils.refreshTable("#table2");
                                //刷新父页面
                            },500);
                        }
                    })
                    layer.close(index);
                });

            },
        }


        $(".inline-search-btn").on('click',function () {
            zzpUtils.refreshTable("#table2");
        })

        //承运人
        var $table2 = zzpUtils.table({
            elem: '#table2',
            isApi: true,
            pagination:true,
            url:'/wmsCustomerFileCarrier/list/'+$("#sskhid2").val(),
            columns: [

                {
                    field: '',
                    checkbox: true,
                    clickToSelect:true
                }, {
                    field: 'cph',
                    title: '车牌号'

                },{
                    field: 'sjxm',
                    title: '司机姓名',
                },{
                    field: 'sjdh',
                    title: '司机电话'
                },{
                    field: 'show_sfyx',
                    title: '激活状态'
                },{
                    field: 'caozuo',
                    title: '操作',
                    events: operateEvent,
                    formatter: operateFormatter2
                }],
            queryParams: function () {//查询条件
                return  zzpUtils.getFormJson($("#searchForm2"));
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            },
        });

        function operateFormatter2(value, row, index) {
            if(row.sfyx==0){//无效
                return [
                    '<a class="layui-btn layui-btn-xs " id="enable2">启用</a>',
                ].join('')
            }else{
                return [
                    '<a class="layui-btn layui-btn-danger layui-btn-xs " id="deleteBtn2">删除</a>',
                    '<a class="layui-btn layui-btn-xs " id="editRow2">编辑</a>'
                ].join('')
            }
        }


        form.on("submit(addbtn2)", function (data) {
            var isRepeat;
            var row={"uuid":Math.random().toString(36),"cph":$("#cph").val(),"sjxm":$("#sjxm").val(),"sjdh":$("#sjdh").val(),"sskhid":$("#sskhid2").val()}
            /*   $table2.bootstrapTable('append', row);*/
            $.ajax({
                type: 'post',
                url: '/zxsdwms/wmsCustomerFileCarrier/save',
                contentType: "application/json",
                async: false,
                data: JSON.stringify(row),
                success: function (res) {
                    /* zzpUtils.refreshTable("#table2");*/
                    $('#table2').bootstrapTable('refresh',{url:'/zxsdwms/wmsCustomerFileCarrier/list/'+$("#sskhid2").val()});
                    setTimeout(function(){
                        $('#form2')[0].reset();
                        /*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                         parent.layer.close(index); //再执行关闭
                         console.info(data);*/
                        top.layer.msg(res.title+","+res.message);

                        //刷新父页面
                    },500);
                }
            })

            var tabledata = $table2.bootstrapTable('getData');
            // zzpUtils.refreshTable("#table2");
            return false;

        });

        //承运车辆编辑保存
        form.on("submit(savebtn2)", function (data) {
            var formObject = {};
            var formArray =$("#form2").serializeArray();
            $.each(formArray,function(i,item){
                formObject[item.name] = item.value;
            });
            var formJson = JSON.stringify(formObject);
            var tabledata = $table2.bootstrapTable('getData');
            $.ajax({
                type: 'post',
                url: '/zxsdwms/wmsCustomerFileCarrier/edit',
                contentType: "application/json",
                async: false,
                data: formJson,
                success: function (res) {
                    /*zzpUtils.refreshTable("#table2");*/
                    $('#table2').bootstrapTable('refresh',{url:'/zxsdwms/wmsCustomerFileCarrier/list/'+$("#sskhid2").val()});
                    setTimeout(function(){
                        $('#form2')[0].reset();
                        /*     var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                         parent.layer.close(index); //再执行关闭*/
                        top.layer.msg(res.title+","+res.message);
                        //刷新父页面
                    },500);
                }
            })
            var tabledata = $table2.bootstrapTable('getData');
            console.log('tabledata', tabledata);
            zzpUtils.refreshTable("#table2");
            return false;

        });




    });

</script>
</html>